package top.january.test.slice;

import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.ToastDialog;
import ohos.global.resource.Resource;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.media.audio.AudioManager;
import top.january.test.MainAbility;
import top.january.test.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;

public class MainAbilitySlice extends AbilitySlice {
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MainAbilitySlice");
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Button mute_button = (Button) findComponentById(ResourceTable.Id_test_button);
        mute_button.setClickedListener(component -> MainAbilitySlice.this.mute());
        Button unmute_button = (Button)findComponentById(ResourceTable.Id_test_button2);
        unmute_button.setClickedListener(Component -> MainAbilitySlice.this.unmute());
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    public void mute() {
        AudioManager m = new AudioManager();
        m.mute(AudioManager.AudioVolumeType.STREAM_MUSIC);
        m.mute(AudioManager.AudioVolumeType.STREAM_RING);

        // 鸿蒙API中没有权限（MODIFY_AUDIO_ROUTING）
        // m.setMasterMute(true);
        HiLog.debug(LABEL_LOG, "click mute");
    }

    public void unmute() {
        AudioManager m = new AudioManager();
        m.unmute(AudioManager.AudioVolumeType.STREAM_MUSIC);
        m.unmute(AudioManager.AudioVolumeType.STREAM_RING);

        // 鸿蒙API中没有权限（MODIFY_AUDIO_ROUTING）
        // m.setMasterMute(true);
        HiLog.debug(LABEL_LOG, "click unmute");
    }
}
